﻿using log4net;
using StoreProject.Forms.SettingForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace StoreProject.Forms
{
    public partial class SettingForm : Form
    {
        ILog _log = LogManager.GetLogger("SettingForm");
        public SettingForm()
        {
            InitializeComponent();
        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            try
            {
                if (e.Node != null && Convert.ToInt32(e.Node.Tag) != 0)
                {
                    this.splitContainer1.Panel2.Controls.Clear();
                    this.splitContainer1.Panel2.Controls.Add(settingDic[e.Node.Text]);
                    settingDic[e.Node.Text].Show();
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message);
            }
        }

        private Dictionary<string, Control> settingDic = null;
        private void SettingForm_Load(object sender, EventArgs e)
        {
            try
            {
                if (treeView1.Nodes[0].Nodes[0].IsExpanded == false)
                {
                    treeView1.Nodes[0].ExpandAll();
                    //treeView1.SelectedNode.ExpandAll();  //展开选中的全部节点
                    //treeView1.Nodes[0].FirstNode.Expand();  //展开第一个节点的全部
                }
                #region 设置右侧页面
                settingDic = new Dictionary<string, Control>();

                CustomerQueryForm sub = new CustomerQueryForm();
                sub.TopLevel = false;
                sub.Dock = DockStyle.Fill;//把子窗体设置为控件
                sub.FormBorderStyle = FormBorderStyle.None;
                settingDic.Add("客户设置", sub);

                WorkingProcedureQueryForm workingProcedureQueryForm = new WorkingProcedureQueryForm();
                workingProcedureQueryForm.TopLevel = false;
                workingProcedureQueryForm.Dock = DockStyle.Fill;//把子窗体设置为控件
                workingProcedureQueryForm.FormBorderStyle = FormBorderStyle.None;
                settingDic.Add("生产工艺设置", workingProcedureQueryForm);

                LineTypeQueryForm lineTypeQueryForm = new LineTypeQueryForm();
                lineTypeQueryForm.TopLevel = false;
                lineTypeQueryForm.Dock = DockStyle.Fill;//把子窗体设置为控件
                lineTypeQueryForm.FormBorderStyle = FormBorderStyle.None;
                settingDic.Add("线型设置", lineTypeQueryForm);

                OperatorQueryForm operatorQueryForm = new OperatorQueryForm();
                operatorQueryForm.TopLevel = false;
                operatorQueryForm.Dock = DockStyle.Fill;//把子窗体设置为控件
                operatorQueryForm.FormBorderStyle = FormBorderStyle.None;
                settingDic.Add("操作员设置", operatorQueryForm);

                orderPrinterSettingForm = new OrderPrinterSettingForm();
                orderPrinterSettingForm.TopLevel = false;
                orderPrinterSettingForm.Dock = DockStyle.Fill;//把子窗体设置为控件
                orderPrinterSettingForm.FormBorderStyle = FormBorderStyle.None;
                settingDic.Add("制令单打印机参数设置", orderPrinterSettingForm);

                //boxNumPrintSettingForm = new BoxNumPrintSettingForm();
                //boxNumPrintSettingForm.TopLevel = false;
                //boxNumPrintSettingForm.Dock = DockStyle.Fill;//把子窗体设置为控件
                //boxNumPrintSettingForm.FormBorderStyle = FormBorderStyle.None;
                //settingDic.Add("条码打印机参数设置", boxNumPrintSettingForm);

                WorkingProcedureNameForm workingProcedureNameForm = new WorkingProcedureNameForm();
                workingProcedureNameForm.TopLevel = false;
                workingProcedureNameForm.Dock = DockStyle.Fill;//把子窗体设置为控件
                workingProcedureNameForm.FormBorderStyle = FormBorderStyle.None;
                settingDic.Add("生产工序名称设置", workingProcedureNameForm);

                WorkingProcedureRemarkForm workingProcedureRemarkForm= new WorkingProcedureRemarkForm();
                workingProcedureRemarkForm.TopLevel = false;
                workingProcedureRemarkForm.Dock = DockStyle.Fill;//把子窗体设置为控件
                workingProcedureRemarkForm.FormBorderStyle = FormBorderStyle.None;
                settingDic.Add("生产工序备注设置", workingProcedureRemarkForm);
                #endregion
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message);
            }
            
        }

        OrderPrinterSettingForm orderPrinterSettingForm = null;
        //BoxNumPrintSettingForm boxNumPrintSettingForm = null;
        private void SettingForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                orderPrinterSettingForm.Dispose();
                orderPrinterSettingForm = null;
                //boxNumPrintSettingForm.Dispose();
                orderPrinterSettingForm = null;
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message);
            }
        }
    }
}
